import pygame.font

class Button():
    def __init__(self, ai_settings, screen):
        """初始化按钮的属性"""
        self.screen = screen
        self.screen_rect = screen.get_rect()
        
        # 设置按钮的尺寸和其他属性
        self.width, self.height = 200, 50
        self.button_color = (0, 255, 0)
        self.text_color = (255, 255, 255)
        self.font = pygame.font.SysFont('nlxjtregular', 30)
        
        # 创建按钮的rect对象，并使其居中
        self.rect1 = pygame.Rect(0, 0, self.width, self.height)
        self.rect1.bottom = self.screen_rect.bottom
        self.rect1.left = self.screen_rect.left
        
        self.rect2 = pygame.Rect(0, 0, self.width, self.height)
        self.rect2.bottom = self.screen_rect.bottom
        self.rect2.right = self.screen_rect.right
        # 按钮的标签只需创建一次
        self.prep_msg1()
        self.prep_msg2()
    
    def prep_msg1(self):
        """将msg渲染为图像，并使其在按钮上居中"""
        self.msg_image1 = self.font.render('重随', True, self.text_color,
            self.button_color)
        self.msg_image1_rect = self.msg_image1.get_rect()
        self.msg_image1_rect.center = self.rect1.center
    
    def prep_msg2(self):
        """将msg渲染为图像，并使其在按钮上居中"""
        self.msg_image2 = self.font.render('确认', True, self.text_color,
            self.button_color)
        self.msg_image2_rect = self.msg_image2.get_rect()
        self.msg_image2_rect.center = self.rect2.center
    
    def draw_button1(self):
        # 绘制一个用颜色填充的按钮，再绘制文本
        self.screen.fill(self.button_color, self.rect1)
        self.screen.blit(self.msg_image1, self.msg_image1_rect)
    
    def draw_button2(self):
        # 绘制一个用颜色填充的按钮，再绘制文本
        self.screen.fill(self.button_color, self.rect2)
        self.screen.blit(self.msg_image2, self.msg_image2_rect)